package com.yjhb.android.sbz.tool;

import android.app.Dialog;
import android.content.Context;
import android.text.Editable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.yjhb.android.sbz.App;
import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.dialog.InputDialog;
import com.yjhb.android.sbz.dialog.TipsDialog;
import com.yjhb.android.sbz.entity.ManagerTask;
import com.yjhb.android.sbz.imps.BaseTextChangedListener;
import com.jojo.android.zxlib.interfaces.Callback;
import com.jojo.android.zxlib.tool.ZxDataTool;
import com.jojo.android.zxlib.tool.ZxSpanTool;
import com.jojo.android.zxlib.tool.ZxToast;

import java.util.HashMap;
import java.util.Map;

/**
 * 创建者 zx
 * 创建时间 2021/1/25 9:45
 */
public class CommonDialogCollect {
    private final String TAG = "CommonDialogCollect";


    /**
     * 15分钟快审
     */
    public static TipsDialog quickTrial(Context context, ManagerTask managerTask) {

        CharSequence content = "开启快审，平台将优先展示曝光，接单人提交做单验证后，你需在快审时间段（08:00-23:00），1个小时内审核，否则将自动通过，请确定后上线！";
        String high1 = "优先展示曝光";
        String high2 = "1个小时内审核";
        int index = content.toString().indexOf(high1);
        content = ZxSpanTool.ColorSpan(content, index, index + high1.length(), context.getResources().getColor(R.color.red_3b));
        index = content.toString().indexOf(high2);
        content = ZxSpanTool.ColorSpan(content, index, index + high2.length(), context.getResources().getColor(R.color.red_3b));
        final TipsDialog tipsDialog = new TipsDialog(context);
        tipsDialog.setTitle("提示");
        if (managerTask.getTask().getAuditFast() == 0) {
//            isOpen = true;
            tipsDialog.setContent(content);
            tipsDialog.setSubmitText("确定上线");
        } else {
//            isOpen = false;
            tipsDialog.setContent("确认关闭快审吗？关闭后任务将不再优先曝光。");
            tipsDialog.setSubmitText("确定关闭");
        }
        tipsDialog.setContentGravity(Gravity.CENTER);

        return tipsDialog;
    }


    /**
     * 增加悬赏人数
     */
    public static InputDialog addNum(Context context) {
        final InputDialog inputDialog = new InputDialog(context);
        inputDialog.setConfirmText("确定");
        inputDialog.setTitleText("增加名额");
        inputDialog.setTipsText("请输入增加的悬赏数量（5个起）");
        inputDialog.getInputView().setHint("请输入数量");
        inputDialog.getInputView().setInputType(0x00002002); //数字类型
        inputDialog.getInputView().addTextChangedListener(new BaseTextChangedListener() {
            @Override
            public void afterTextChanged(Editable s) {
                super.afterTextChanged(s);
                if (s != null && s.toString().contains(".")) {
                    String content = s.toString().replace(".", "");

                    inputDialog.getInputView().setText(content);
                    inputDialog.getInputView().setSelection(content.length());
                }
            }
        });
        return inputDialog;
    }


    public static InputDialog addMoney(Context context) {
        final InputDialog inputDialog = new InputDialog(context);
        inputDialog.setConfirmText("确定");
        inputDialog.setTitleText("提高赏金");
        inputDialog.setTipsText("请输入提高的金额（至少0.2元）");
        inputDialog.getInputView().setHint("请输入金额");
        inputDialog.getInputView().setInputType(0x00002002); //数字类型
        return inputDialog;
    }


    /**
     * 任务刷新
     */
    public static TipsDialog taskRefresh(Context context) {
        final TipsDialog tipsDialog = new TipsDialog(context);
        tipsDialog.setTitle("提示");
        tipsDialog.setContent("当前剩余刷新次数:" + App.userInfo.getPayFlushCount()+ "\n" +
                "会员每日首次刷新免费，确定刷新？");
        tipsDialog.setContentGravity(Gravity.CENTER);
        tipsDialog.setSubmitText("确定刷新");
        return tipsDialog;
    }


    /**
     * 实名认证弹窗
     */
    public static void showVerified(Context context, Callback<Map<String, String>> callback) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_verified, null, false);
        final EditText et_name = view.findViewById(R.id.et_name);
        final EditText et_idCard = view.findViewById(R.id.et_idCard);
        View btn_bind = view.findViewById(R.id.bind_tv);
        View close_iv = view.findViewById(R.id.close_iv);
        final Dialog dialog = DialogTool.createDialog(context, view);
        btn_bind.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Tool.isEditEmpty(et_name)) {
                    ZxToast.showBottomToastLight("请输入姓名");
                    return;
                }
                if (Tool.isEditEmpty(et_idCard)) {
                    ZxToast.showBottomToastLight("请输入身份证号");
                    return;
                }
                if (!ZxDataTool.isIdCard(et_idCard.getText().toString())) {
                    ZxToast.showBottomToastLight("身份证号有误，请检查身份账号是否输入正确");
                    return;
                }
                Map<String, String> map = new HashMap<>();
                map.put("name", et_name.getText().toString());
                map.put("idCard", et_idCard.getText().toString());
                callback.callback(map);
                dialog.dismiss();
            }
        });
        close_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }
}
